package adv6;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ClsTest2 {

	public static void main(String[] args) throws Exception {
		Class c = Staff.class;
		// 无参的构造方法
		// Staff f = (Staff) c.newInstance();
		// System.out.println(f);
		Constructor cr = c.getDeclaredConstructor(String.class, String.class);
		cr.setAccessible(true);// 取消对private的限制
		// 访问构造
		Staff f = (Staff) cr.newInstance("陈达星", "09091");
		System.out.println(f);

		Field fwork = c.getDeclaredField("work");
		fwork.setAccessible(true);
		// 访问属性
		fwork.set(f, "副总经理");
		System.out.println(f);

		Method m = c.getDeclaredMethod("staffshow");
		m.setAccessible(true);
		// 调用方法
		m.invoke(f);

	}

}
